<?php
	require '../../feed/config/config.php';
	session_start();
	$ConnfigRs=mysqli_fetch_array(mysqli_query($con,"select * from config where id='1'"));
	if(empty($_SESSION['member'])){
	    echo "<script>location='../index.php';</script>";
	}
	if($_GET['ops']=="logout"){
	    session_destroy();
	    session_start();
	    $_SESSION['url']="https://edu.yudur.cn/index/index.php";
	    echo "<script>alert('您已成功退出');location='../index.php';</script>";
	}
	if($_POST['submit']){
	   $clubRs=mysqli_fetch_array(mysqli_query($con,"select * from club where addKey='".$_POST['addKey']."'")); 
	   if($clubRs['name']!=""){
	       $infoRs=mysqli_fetch_array(mysqli_query($con,"select * from clubUser where clubId='".$clubRs['id']."' and user='".$_SESSION['member']."'"));
	       if($infoRs['user']==$_SESSION['member']){
	           echo "<script>alert('您已是社团成员或已申请加入，暂时无法再次加入!');location='./index.php';</script>";
	       }else{
	           if($clubRs['state']=="1"){
    	           $clubIdentityRs=mysqli_fetch_array(mysqli_query($con,"select * from clubIdentity where identityName='未审核新用户' and clubId='".$clubRs['id']."'"));
    	           mysqli_query($con,"INSERT INTO `clubUser` (`id`,`user`,`clubId`,`addTime`,`identityId`,`state`) VALUES ('','".$_SESSION['member']."','".$clubRs['id']."','".date("Y/m/d H:i:s")."','".$clubIdentityRs['id']."','0')");
    	           echo "<script>alert('您要加入的社团为：".$clubRs['name']."，您已成功提交申请，请耐心等待".$clubRs['name']."管理员审核！');location='./index.php';</script>";
    	       }else{
    	           echo "<script>alert('您要加入的社团为：".$clubRs['name']."，由于社团状态异常，暂时无法加入!');location='./index.php';</script>";
    	       }
	       }
	       
	   }else {
	       echo "<script>alert('社团邀请码无效!');location='./index.php';</script>";
	   }
	}
?>
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8"/>
    <title>社团中心 - 加入社团</title>
    <script type="text/javascript" src="../js/base-loading.min.js"></script>
    <script type="text/javascript" src="../js/layui.js"></script>
    <link rel="stylesheet" href="../css/style.css"/>
    <link rel="stylesheet" href="../css/layui.css"/>
  </head>
  <body>
    <div class="s_header w">
      <div class="s_header_top w">
        <div class="header_top w1000 auto">
          <div class="header_top_fl fl">欢迎访问<?php echo $ConnfigRs['name'];?></div>
          <div class="header_top_fr fr"><span class="header_email dib"></span><span class="header_tel dib"></span>
            <div class="cb"></div>
          </div>
          <div class="cb"></div>
        </div>
      </div>
      <div class="s_header_nav w">
        <div class="header_nav w1000 auto">
          <div class="logo fl"><a href="index.html"><img src="http://www.huayu.edu.cn/template/huayu/listimages/logo.png" alt=""/></a></div>
        </div>
      </div>
    </div>
    <div class="banner">
      <div id="banner" class="dv_5"><a href="" style=" background:url(../images/hy.png) center center no-repeat; display: block; z-index: 1; " class="d1"></a><a href="" style=" background:url(images/banner2.png) center center no-repeat; display: block; z-index: 1; " class="d1"></a><a href="" style=" background:url(images/banner3.png) center center no-repeat; display: block; z-index: 1; " class="d1"></a>
      </div>
    </div>
    <div class="s_cen w">
      <div class="center w1000 auto">
          <br />
                <p><a href="../index.php">首页</a> / <a href="./index.php">社团中心</a> / 加入社团</p>
              <br /><br />
              <?php
                    $club=mysqli_query($con,"select * from club order by id asc");
        			while($rs=mysqli_fetch_array($club)){
        			    if($rs['id']!=""){
        			        if($rs['state']=="0"){
        			            $state="待审核";
        			        }elseif($rs['state']=="1"){
        			            $state="正常";
        			        }elseif($rs['state']=="-1"){
        			            $state="以封禁或已注销";
        			        }
        			        echo "社团名称：<a href='./club.php?clubId=".$rs['id']."'>".$rs['name']."</a> | 创建时间：".$rs['regTime']."  | 状态：".$state." | 操作：<a href='?addKey=".$rs['addKey']."'>申请加入</a><br />";
        			    }else{
        			        echo "暂无更多！";
        			    }
        			}
                  ?>
                  <br /><br />
        <div class="cen_one">
          <div class="cen_one_fl fl">
              
            <div class="jqal_top">
              <div class="jqal_top_tit fl">加入社团</div>
              <div class="cb"></div>
            </div>
            <div class="jqal_bom mychgPic">
              <div id="myFocus" class="mF_liuzg">
                <form method="post" action="./joinclub.php">
                    <input type="text" name="addKey" class="layui-input" placeholder="请输入社团邀请码" value="<?php if($_GET['addKey']){ echo $_GET['addKey'];}?>">
                    <br />
                    <br />
                    <input type="submit" name="submit" class="layui-btn" value="申请加入">
                </form>   
              </div>
            </div>
          </div>
          <div class="cb"></div>
        </div>
      </div>
    </div>
    <div class="s_footer w">
      <div class="footer w1000 auto">
        <div class="footer_fl fl">
          <div class="footer_logo"><a href=""><img src="http://www.huayu.edu.cn/template/huayu/images/logo.png"  alt="" width="100%"/></a></div>
          <div class="footer_line"></div>
          <div class="footer_fl_ul">
            
          </div>
          <div class="cb"></div>
          <div class="footer_fl_record"></div>
        </div>
        <div class="footer_fr fr">
          <div class="footer_fr_top"></div>
          <div class="footer_line"></div>
         
          <div class="footer_from">｜<a href="" target="_blank">XXX</a></div>
        </div>
      </div>
    </div>
    <script type="text/javascript" src="../js/jquery-1.8.1.min.js"></script>
    <!--首页banner特效-->
    <script type="text/javascript" src="../js/banner.js"></script>
    <script type="text/javascript" src="../js/main.js"> </script>
    <script type="text/javascript" src="../js/jquery.SuperSlide.2.1.1.js"></script>
</body>
</html>